﻿using LianXi1013.Entity;
using LianXi1013.Entity.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LianXi1013.Repostory.User
{
    public class UserInforRepostory : IUserInforRepostory
    {
        private readonly ProjectDbContext projectDbContext;

        public UserInforRepostory(ProjectDbContext projectDbContext)
        {
            this.projectDbContext = projectDbContext;
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public UserInfor LoginUser(string name, string password)
        {
            var list = projectDbContext.UserInfor.FirstOrDefault(u => u.UserName == name && u.Password == password);
            return list;
        }

        /// <summary>
        /// 查询是否有该用户名
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public UserInfor GetUserName(string name)
        {
            var list = projectDbContext.UserInfor.FirstOrDefault(u => u.UserName == name);
            return list;
        }

        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="u"></param>
        /// <returns></returns>
        public bool AddUser(UserInfor u)
        {
            projectDbContext.UserInfor.Add(u);
            return projectDbContext.SaveChanges() > 0;
        }
    }
}
